<?php
/*
命令组件
*/
class Com_shell extends Acan{
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
	}
	function netstat_ip($port=80){
		$os = Afun_get_os();
		$localip = $_SERVER['SERVER_ADDR'];
		if($os == 'Linux'){
			$cmd = "netstat -an|grep \"$port\"";
		}else{
			$cmd = "netstat -an|find \"$port\"";
		}
		$data = Afun_run_cmd($cmd);
		$data = preg_replace('/([ ]+)/',' ',$data);
		$drr = explode("\n",$data);
		foreach ($drr as $k => $v) {
			if(empty($v)){continue;}
			$vrr = explode(' ',$v);
			if($os == 'Linux'){
				$ip2 = $vrr[4];
				$ipstat = $vrr[5];
			}else{
				$ip2 = $vrr[3];
				$ipstat = $vrr[4];
			}
			if($ip2==$localip.':80'){continue;}
			$iprr = explode(":",$ip2);
			if(empty($ips[$iprr[0]]['num'])){
				$ips[$iprr[0]]['num'] = 1;
				$ipinfo = Afun_ip_info($iprr[0]);
				$ips[$iprr[0]]['city'] = $ipinfo['city'];
				$ips[$iprr[0]]['add'] = $ipinfo['add'];
			}else{
				$ips[$iprr[0]]['num']++;
			}
			if(empty($ips[$iprr[0]][$ipstat])){
				$ips[$iprr[0]][$ipstat] = 1;
			}else{
				$ips[$iprr[0]][$ipstat]++;
			}
			if(empty($status[$ipstat])){$status[$ipstat]=1;}else{$status[$ipstat]++;}
			if(empty($link_num)){$link_num=1;}else{$link_num++;}
		}
		$obj->ips = $ips;
		$obj->status = $status;
		$obj->link_num = $link_num;
		return $obj;
	}

}

?>